import paramiko
import sys
#host=sys.argv[1]
#user=sys.argv[2]
#password=sys.argv[3]
#cmd=sys.argv[4]
try:
    x=sys.argv
    _,host,user,password,*cmd=x

    print(host,user,password,cmd)
    l_password = password
    l_host = host
    l_user = user
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(l_host, username=l_user, password=l_password)    
    transport = ssh.get_transport()
    session = transport.open_session()
    session.set_combine_stderr(True)
    session.get_pty()
    #for testing purposes we want to force sudo to always to ask for password. because of that we use "-k" key
    session.exec_command(cmd)
    stdin = session.makefile('wb', -1)
    stdout = session.makefile('rb', -1)
    #you have to check if you really need to send password here 
    stdin.write(l_password +'\n')
    stdin.flush()
    for line in stdout.read().splitlines():        
        print ('host: %s: %s' % (l_host, str(line, encoding = "utf-8")))
except:
    print('请注意格式：remote.exe ip username password command')
    a=input('任意键退出')
